<#assign upName = "${table.entityName}">
<#assign lowName = "${table.entityPath}">
<#assign packageName = "${'${package.Controller}'?replace('.controller','')}">

<#function getComment>
    <#local names = "">
    <#list table.fields as node>
    <#local names = names +node.name+":"+node.comment+" ">
    </#list>
    <#return "{"+ names + "}">
</#function>

<#--   ${getComment()}    获取对象的json字符串-->

package ${package.Controller};
import ${package.Entity}.${upName};
import ${package.Service}.${upName}Service;
import ${packageName}.common.ApiResult;
import ${packageName}.common.ApiPageResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.*;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
<#if swagger2>
import io.swagger.annotations.Api;
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */

<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("/${lowName}")
<#if swagger2>
@Api(tags = "${table.comment}操作")
</#if>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    @Autowired
    ${upName}Service ${lowName}Service;

    @ApiOperation("获取${table.comment}")
    @ApiImplicitParam(name = "id",value = "${table.comment}id",required = true)
    @GetMapping("/get")
    public ApiResult<${upName}> get(@RequestParam String id) {
        return ApiResult.success(${lowName}Service.getById(id));
    }

    @ApiOperation("添加${table.comment}")
    @PostMapping("/add")
    public ApiResult<${upName}> add(@RequestBody ${upName} ${lowName}) {
        ${lowName}Service.save(${lowName});
        return ApiResult.success(${lowName});
    }

    @ApiOperation("修改${table.comment}")
    @PostMapping("/update")
    public ApiResult<${upName}> update(@RequestBody ${upName} ${lowName}) {
        return ApiResult.success(${lowName}Service.update${upName}(${lowName}));
    }

    @ApiOperation("删除${table.comment}")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    @GetMapping("/delete")
    public ApiResult<Boolean> delete(@RequestParam String id) {
        return ApiResult.success(${lowName}Service.removeById(id));
    }

    @ApiOperation(value = "获取${table.comment}分页",notes = "页码从1开始")
    @ApiImplicitParams(value = {
    @ApiImplicitParam(name = "page",value = "页码"),
    @ApiImplicitParam(name = "size",value = "每页条数")
    })
    @GetMapping("/page")
    public ApiPageResult<List<${upName}>> page(@RequestParam Long page, @RequestParam Long size) {
        final Page<${upName}> ${lowName}Page = new Page<>(page,size);
        final Page<${upName}> pageResult = ${lowName}Service.page(${lowName}Page);
        return ApiPageResult.success(pageResult.getRecords(), page, size, pageResult.getTotal());
    }

    @ApiOperation(value = "${table.comment}统计")
    @GetMapping("/count")
    public ApiResult<Integer> count() {
        return ApiResult.success(${lowName}Service.count());
    }
}

